package com.android.common.utils;

import static android.content.Context.NOTIFICATION_SERVICE;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationChannelGroup;
import android.app.NotificationManager;
import android.content.Context;

public class NotificationUtil {

    /**
     * 显示通知栏
     *
     * @param id           id
     * @param notification notification
     */
    public static void notify(Context context, int id, Notification notification) {
        NotificationManager manager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
        if (manager != null) {
            manager.notify(id, notification);
        }
    }


    public static void createNotification(Context context,String channelId,String channelName) {
        NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        NotificationChannel channel = new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_HIGH);
        channel.enableLights(true);
        channel.enableVibration(true);
        channel.setShowBadge(true);
        //notificationChannel.setSound(Uri.parse("android.resource://包名/raw/铃声文件"), null);    //设置自定义铃声
        nm.createNotificationChannel(channel);
    }

    public static void createNotificationWithGroup(Context context,String groupId,String groupName,String channelId,String channelName) {
        NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        NotificationChannelGroup ncg = new NotificationChannelGroup(groupId, groupName);
        nm.createNotificationChannelGroup(ncg);
        NotificationChannel notificationChannel = new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_HIGH);
        notificationChannel.setGroup(groupId);
        notificationChannel.enableLights(true);
        notificationChannel.enableVibration(true);
        //notificationChannel.setSound(Uri.parse("android.resource://包名/raw/铃声文件"), null);    //设置自定义铃声
        nm.createNotificationChannel(notificationChannel);
    }

}
